#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
using namespace std;

int T,N;
int a[maxn];
int pre[2020][2020];
unordered_map<int,int> ind;
inline void read(int &x){
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    x = s*w;
}
void init(){
	ind.clear();
	for(int i = 1;i<=N;i++) memset(pre[i],0,4*N+10);
	for(int i = 1;i<=N;i++) ind[a[i]] = i;
	for(int i = 1;i<=N;i++){
		for(int j = 1;j<=N;j++){
			pre[i][j] = pre[i][j-1] + (a[j] == a[i]);
		}
	}
}
void solve(){
	ll ans = 0;
	for(int i = 1;i<=N-1;i++){
		for(int k = i+2;k<=N;k++){
			if((a[i] + a[k]) %2 == 1) continue;
			int mid = (a[i]+a[k])>>1;
			if(ind.count(mid) == 0) continue;
			int id = ind[mid];
			ans += pre[id][k-1] - pre[id][i];
		}
	}
	cout<<ans<<'\n';
}
int main(){
	// debug;
	// ios;
	cin>>T;
	while(T--){
		cin>>N;
		for(int i = 1;i<=N;i++) read(a[i]);
		init();
		solve();
	}
	
	return 0;
}